<?php
/**
 * 新闻列表
 */

namespace app\pc\model;


use app\common\model\Model;

class News extends Model
{

    const TABLE_NAME = 'news_list';
    const CACHE_EXPIRE_LEVEL = self::CACHE_EXPIRE_LEVEL_2;

    protected $name = self::TABLE_NAME;

    public static function getList($page=1,$limit=self::LIMIT){
        return self::commonQuery(self::TABLE_NAME)
               ->where(['news_is_publish'=>1])
              ->order('news_time desc')
              ->page($page,$limit)
              ->select();
    }
    public static function handleList($list)
    {
        if(empty($list))
        {
            return [];
        }
        foreach ($list as $key=>$val)
        {
            $list[$key]['news_time']=date('Y-m-d',$val['news_time']);
        }
        return $list;
    }
    public static function handleInfo($news_info)
    {
        $news_info['news_time']=date('Y-m-d H:i',$news_info['news_time']);
        return $news_info;
    }
    public static function getNewsInfo($news_id)
    {
        return self::commonQuery(self::TABLE_NAME,self::CACHE_EXPIRE_LEVEL)
            ->where(['news_id'=>$news_id])
            ->find();
    }
    public static function getNewsContent($news_id)
    {
        return self::commonQuery('news_content',self::CACHE_EXPIRE_LEVEL_4)->where(['content_news_id'=>$news_id])->value('content_text');
    }
}